package com.sha.mumbailocal.server.corn;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sha.mumbailocal.server.impl.ContentToPersistentObjectTransformer;
import com.sha.mumbailocal.server.impl.CsvContentParser;
import com.sha.mumbailocal.server.impl.GAEDataStorePersister;
import com.sha.mumbailocal.server.impl.UrlContentProvider;
import com.sha.mumbailocal.shared.Pair;

public class ERailTrainSchedulePersisterJob extends AbstractContentPersisterJob {
	public ERailTrainSchedulePersisterJob() {

		String trainNo = "10763";

		setContentProvider(new UrlContentProvider(
				"http://erail.in/Rail/GetTrainRoute.aspx?TrainID=10763&Station_From=ABH&Station_To=BUD&Language=0"));

		CsvContentParser contentParser = new CsvContentParser();
		contentParser.setRecordDelimeter("\\^");
		contentParser.setFieldDelimiter("~");

		contentParser.setFields(new String[] { "srNo", "stationCode",
				"stationName", "arrival", "departure", "uk", "uk", "uk", "uk",
				"uk", "uk", "uk" });
		setContentParser(contentParser);

		List<Pair<String, Map<String, String>>> pairs = new ArrayList<Pair<String, Map<String, String>>>();
		Map<String, String> startStationMap = new HashMap<String, String>();
		startStationMap.put("code", "stationCode");
		startStationMap.put("name", "stationName");
		pairs.add(Pair.create(
				"com.sha.mumbailocal.server.model.Station$station",
				startStationMap));
		Map<String, String> trainStopMap = new HashMap<String, String>();
		trainStopMap.put("station", "$station");
		trainStopMap.put("arrival", "arrival");
		trainStopMap.put("departure", "departure");
		pairs.add(Pair.create(
				"com.sha.mumbailocal.server.model.TrainStop$trainstop",
				trainStopMap));
		ContentToPersistentObjectTransformer contentTransformer = new ContentToPersistentObjectTransformer(
				pairs);
		setContentTransformer(contentTransformer);

		setContentPersister(new GAEDataStorePersister());
	}
}
